<template>
  <el-form :model="form" label-width="120px">
    <el-form-item label="标题">
      <el-input v-model="form.title" />
    </el-form-item>
    <el-form-item label="分类">
      <el-select v-model="form.category" placeholder="el-select">
        <el-option :label="item.classname" :value="item.classid" v-for ="(item,index) in categoryList" :key="index" />
        <el-option label="Zone two" value="beijing" />
      </el-select>
    </el-form-item>
    <el-form-item label="推荐">
      <el-switch v-model="form.red" />
    </el-form-item>
    <el-form-item label="描述">
      <el-input v-model="form.content" type="textarea" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">添加</el-button>
      <el-button>Cancel</el-button>
    </el-form-item>
  </el-form>
</template>

<script lang="ts" setup>
import { addArticle,getCategory } from "@/api/news.ts"
import { reactive,shallowRef } from 'vue'

let categoryList = shallowRef([]);

const getData = async() => {
	const res = await getCategory()
	console.log(res)
	categoryList =  res.data
		console.log(categoryList);
}


// do not use same name with ref
const form = reactive({
  title: '',
  category: '',
  red: '',
  content: '',
})

const onSubmit = async () => {
	const res = await addArticle({form})
	console.log(res)
}

getData();

</script>